#coding=utf-8
#@Time:2019\10\15 0015 15:05
#@Author:希哥
#@File:search.py

import mysql_getData

'''
    单个结果查询
'''
def search(sql):
    connect = mysql_getData.mysql_connect()[0]  # connect是由connect_mysql函数返回的第一个值
    cursor = connect.cursor()
    # 执行sql语句
    cursor.execute(sql)
    result = cursor.fetchall()
    connect.commit()  # 实例提交命令
    final_result = result[0][0]
    return final_result

'''
    多个结果查询
'''
def search_total(sql):
    connect = mysql_getData.mysql_connect()[0]  # connect是由connect_mysql函数返回的第一个值
    cursor = connect.cursor()
    # 执行sql语句
    cursor.execute(sql)
    result = cursor.fetchall()
    connect.commit()  # 实例提交命令
    final_result = result
    return final_result  #返回全部查询结果

'''
    更新数据库
'''
def update(sql):
    connect = mysql_getData.mysql_connect()[0]  # connect是由connect_mysql函数返回的第一个值
    cursor = connect.cursor()
    # 执行sql语句
    cursor.execute(sql)
    connect.commit()  # 实例提交命令
    print u'更新成功'

if __name__=='__main__':
    search("SELECT id FROM hp_user.user WHERE name = 'Holy'")
    # update("UPDATE hp_mall.orders SET dt = '1' WHERE user_id = '26321297743285206' and dt = '0' and type = 'CERTIFICATE'")
